<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
layout:decorator="layout">
  <head>
  	<title>备忘录管理</title>
  	<script>
  	$(function() {
  		setMenu("备忘");
  		var id = $('#evaluateId').val();
  		var flgs = $('#flgs').val();
  		/* function getNewline(val) {  
  		    var str = new String(val);  
  		    var bytesCount = 0;  
  		    var s="";
  		    for (var i = 0 ,n = str.length; i < n; i++) {  
  		        var c = str.charCodeAt(i);  
  		        //统计字符串的字符长度
  		        if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {  
  		            bytesCount += 1;  
  		        } else {  
  		            bytesCount += 2;  
  		        }
  		        //换行
  		        s += str.charAt(i);
  		        if(bytesCount>=80){  
  		        	s = s + '<br/>';
  		        	//重置
  		        	bytesCount=0;
  		        }
  		    }
  		    return s;  
  		}; */
  		
  		//删除
  	   $('#memoTable').on('click', '.edit-button:nth-child(1)', function(e){
  			if(!confirm("确定要删除这条备忘吗？")) return;
  			var $this = $(this);
  			var $parents = $this.parents('tr');
  			var id = $parents.children('td').eq(4).text();
  			$.ajax({
  				  url: 'updatememo',
  				  type: 'POST',
  				  dataType : "json",
  				  data: {
  					  id : id,
  					  flg : "1"
  				  },
  				  success: function(obj){
  					  if(obj.success){
  						  $("#page").pageReload();
  					  }
  				  }
  				});
  		});
  	 //编辑
  	 $('#memoTable').on('click', '.edit-button:nth-child(2)', function(e){
		 var $this = $(this);
		 var $tr = $this.parents('tr').children('td');
		 var id = $tr.eq(4).text();
		 $(".context").val($tr.eq(0).text().replace(/\s/g, ""));
		 $('.name').html('<option>'+$tr.eq(1).text()+'</option>');
		 $(".name").attr("disabled", true);
		 $(".id").val(id);
		 $(".flg").val("0");
  	     $("#memoMask").clone().dilog({title:"编辑",width:"630px"});
	 });
  	 var $temp = $("#memoMask").clone();
  	 //添加备忘录
 	 $("#addMemo").on('click',function(){
		$(".context").val("");
		$(".name").val("");
		$(".id").val("");
		$(".flg").val("2");
		if(flgs==0){//比赛组
			$temp.clone().dilog({title:"添加备忘",width:"630px"});
		}else{//比赛
			var bs_name = $("#bs_name").val();
			$('.name').html('<option>'+bs_name+'</option>');
			$(".name").attr("disabled", true);
			$("#memoMask").clone().dilog({title:"添加备忘",width:"630px"});
		}
	 });
  	 
  	 //条件搜索
  	 $(".list-sear-btn").on('click',function(e){
  		 $("#page").page({url:"getWorkData",data:{timeFrom :$('.list-sear-text1')[0].value,timeTo : $('.list-sear-text1')[1].value,context : $('.list-sear-text2').val().trim(),groupId:id,flgs:flgs},success:function(obj){
  			 $.each(obj.obj.content, function(i,v){
  				 v.createdAt = new Date(v.createdAt).Format("yyyy-MM-dd HH:mm");
  				 /* v.context = getNewline(v.context); */
  			 });
  			 $("#pageData").loadData(obj.obj);
  		 }});		
  	 });
  	$(".list-sear-btn").click();
  	
  	 //提交表单
  	 $(document).on('click', '.tijiao' ,function(e){
		  var flg = $(".flg").val();//0编辑 1删除 2添加
		  var tempContext = $(".context")[1].value;
		  var id;
		  if(tempContext==""){
			  alert("请填写内容!");
			  return;
		  }
		  if(flg==2){//添加备忘
			  if(flgs==0){//比赛组添加
				  id = $(".name")[1].value;
			  }else{//比赛添加
				  id = $('#evaluateId').val();
			  }
		  }else{//编辑 删除
			  id = $(".id").val();
		  }
		  if(id==-1){
			  alert('请选择比赛名称!');
			  return;
		  }
		  $.ajax({
			  url: 'updatememo',
			  type: 'POST',
			  dataType : "json",
			  data: {
				  id : id,
				  flg : flg,
				  context : tempContext
			  },
			  success: function(obj){
				 if(obj.success){
					  $(".dilog").remove();
					  $("#page").pageReload();
				  } 
			  }
			});
	   }); 
  	});
  	
	var beginAt = new Date().DateAdd(-7).Format("yyyy-MM-dd");
	var endAt = new Date().Format("yyyy-MM-dd");
	var dateRange = new pickerDateRange('listStageDate', {
        isTodayValid : false,
        startDate:beginAt,
        endDate:endAt,
        defaultText : ' 至 ',
        theme : 'ta',
        success : function(obj) {
        	if(obj.endDate == ''){
        		obj.endDate = obj.startDate;
        	}
        	if(obj.endDate == ''){
        		return;
        	}
        }
    });
  </script>
  	
  </head>
  <body>
	<div layout:fragment="content" class="content" id="modal">
	
	<div class="modal">
	<input id="evaluateId" type="hidden" th:value="${id}" />
	<input id="flgs" type="hidden" th:value="${flgs}" />
	<input id="bs_name" type="hidden" th:value="${bsName}" />
	
	<!-- 条件搜索栏 -->
    <div class="list-sears">
    	<div class="list-sear-box">
    		<input class="list-sear-text1" type="text"  readonly="readonly" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" placeholder="备忘开始时间" value=""/>
    		<span>至</span>
    		<input class="list-sear-text1" type="text"  readonly="readonly" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" placeholder="备忘结束时间" value=""/>
    	</div>
    	<div class="list-sear-box">
    		<input class="list-sear-text2" type="text"  placeholder="备忘内容" value=""/>
    	</div>
    	<div class="list-sear-btn" >搜索</div>
   	</div>
	<div class="detail">
		<div class="detail-table">
	   	<h4 class="detail-table-title">备忘列表
	   	<span class="detail-table-more"><a class="edit-button right2"  id="addMemo">添加备忘</a></span>
	   	</h4>
	    <div class="table_list">
              <div class="table-overflow">
              <table id="memoTable" class="table table-layout">
                  <thead>
                      <tr>
                          <th width="40%">备忘内容</th>
                          <th width="25%">所属比赛</th>
                          <th width="15%">备忘时间</th>
                          <th width="20%">操作</th>
                          <th style="display:none;">id</th>
                      </tr>
                  </thead>
                  <tbody>
                  <script type="text/template" id="pageData">
					#for(data:content)#
						<tr>
							<td class="remark" title=" #{data.context}# ">#{data.context}#</td>
							<td>#{data.name}#</td>
							<td>#{data.createdAt}#</td>
							<td>
								<a class="edit-button right-do">删除</a>
								<a class="edit-button right-do">编辑</a>
							</td>
							<td style="display:none;">#{data.id}#</td>
						</tr>
					#endfor#
					</script>
                   </tbody>
                </table>
                <div id="page"></div>
            </div>
         </div>
         </div>
	</div>
	</div>
	
	<div id="memoMask"  style="display:none">
		<form action="updatememo" >
		<div class="mask_div">
			<label class="form-label-new ">评论内容 :</label>
			<div class="mask"><textarea cols="30" rows="5"  style="float:left;max-width: 628px;line-height:2.0" class="context input-newlarge3" name="" ></textarea></div>
		</div>
		<div class="mask_div">
			<label class="form-label-new ">比赛名称 :</label>
			<div class="mask">
			<select class="name input-newlarge3"  style="float:left;">  
	            <option value="-1">---请选择比赛名称---</option>  
	            <option  th:each="list:${list}" th:value="${list.id}" th:text="${list.name }"></option>
    		</select>
			</div>
		</div>
		<div class="mask_div"><input class="tijiao edit-button" type="button" value="提交" /></div>
		<input class="id" type="hidden"  />
		<input class="flg" type="hidden"  />
		</form>
	</div>

	</div>
  </body>
</html>